/**
 * v-debounce
 * 防抖
 * 接收参数：string类型/Ref<string>类型/Reactive<string>类型
 */
const debounce = {
	bind(el, binding) {
		if (typeof binding.value !== "function") {
			throw "callback must be a function";
		}
		let timer = null
		el.__handleClick__ = () => {
			if (timer) {
				clearInterval(timer);
			}
			timer = setTimeout(() => {
				binding.value();
			}, 500);
		}
		el.addEventListener("click", el.__handleClick__);
	},
	unbind(el) {
		el.removeEventListener("click", el.__handleClick__);
	}
};
export default debounce;